package com.ruoyi.web.controller.base;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BaseRiver;
import com.ruoyi.base.service.IBaseRiverService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 河流Controller
 * 
 * @author ruoyi
 * @date 2025-07-27
 */
@RestController
@RequestMapping("/base/river")
public class BaseRiverController extends BaseController
{
    @Autowired
    private IBaseRiverService baseRiverService;

    /**
     * 查询河流列表
     */
//    @PreAuthorize("@ss.hasPermi('base:river:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseRiver baseRiver)
    {
        startPage();
        List<BaseRiver> list = baseRiverService.selectBaseRiverList(baseRiver);
        return getDataTable(list);
    }

    //    @PreAuthorize("@ss.hasPermi('base:river:listall')")
    @GetMapping("/listall")
    public AjaxResult listall(BaseRiver baseRiver)
    {
        List<BaseRiver> list = baseRiverService.selectBaseRiverList(baseRiver);
        return AjaxResult.success(list);
    }

    /**
     * 导出河流列表
     */
//    @PreAuthorize("@ss.hasPermi('base:river:export')")
//    @Log(title = "河流", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseRiver baseRiver)
    {
        List<BaseRiver> list = baseRiverService.selectBaseRiverList(baseRiver);
        ExcelUtil<BaseRiver> util = new ExcelUtil<BaseRiver>(BaseRiver.class);
        util.exportExcel(response, list, "河流数据");
    }

    /**
     * 获取河流详细信息
     */
    //@PreAuthorize("@ss.hasPermi('base:river:query')")
    @GetMapping(value = "/getinfo/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID)
    {
        return success(baseRiverService.selectBaseRiverByID(ID));
    }

    /**
     * 新增河流
     */
    //@PreAuthorize("@ss.hasPermi('base:river:add')")
    //@Log(title = "河流", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BaseRiver baseRiver)
    {
        return toAjax(baseRiverService.insertBaseRiver(baseRiver));
    }

    /**
     * 修改河流
     */
    //@PreAuthorize("@ss.hasPermi('base:river:edit')")
    //@Log(title = "河流", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody BaseRiver baseRiver)
    {
        return toAjax(baseRiverService.updateBaseRiver(baseRiver));
    }

    /**
     * 删除河流
     */
    //@PreAuthorize("@ss.hasPermi('base:river:remove')")
    //@Log(title = "河流", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{IDs}")
    public AjaxResult remove(@PathVariable String[] IDs)
    {
        return toAjax(baseRiverService.deleteBaseRiverByIDs(IDs));
    }

    @GetMapping("/treeList")
    public AjaxResult treeList(){
        return AjaxResult.success(baseRiverService.treeList());
    }
}
